/*
封装了wx.request
pararms:url:通过config.js可以设置读取url host
        data:用于接收参数
        method:用于指定请求方法
*/
import config from '../configs/config'

export default (url,data = {},method = 'GET') => {
    return new Promise((resolve,reject) => {
        wx.request({
            url : config.host + url,
            data,
            method,
            header:{
                // cookie: wx.getStorageSync('cookies')?wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1):''
                // wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U'))
                cookie: wx.getStorageSync('cookies')?wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1):''
            },
            success:(res) => {
                if(data.isLogin){
                    wx.setStorage({
                        key:"cookies",
                        data:res.cookies
                      })
                }
              resolve(res.data);
          },
          fail: (err) =>{
              reject(err);
          }
          })
    })
}